<template>
<div>
 <v-nav :path="path" :title="title"></v-nav>  

<div class="content">
  <div class="list-block">
    <ul>
      <!-- Text inputs -->
      <li>
        <div class="item-content">
          <div class="item-media"><i class="icon icon-form-name"></i></div>
          <div class="item-inner">
            <div class="item-title label">真实姓名</div>
            <div class="item-input">
              <input type="text" id="name" placeholder="真实姓名" v-model="name">
            </div>
          </div>
        </div>
      </li>

       <li>
        <div class="item-content">
          <div class="item-media"><i class="icon icon-form-name"></i></div>
          <div class="item-inner">
            <div class="item-title label">支付宝账号</div>
            <div class="item-input">
              <input type="text" id="alipayAccount"  placeholder="支付宝账号" v-model="alipayAccount" >
            </div>
          </div>
        </div>
      </li>
      <li>
        <div class="item-content">
          <div class="item-media"><i class="icon icon-form-mobile"></i></div>
          <div class="item-inner">
            <div class="item-title label">手机号码</div>
            <div class="item-input">
              <input type="number"  id="mobile" placeholder="手机号码" v-model="mobile">
            </div>
          </div>
        </div>
      </li> 


       <li class="align-top">
        <div class="item-content">
          <div class="item-media"><i class="icon icon-form-comment"></i></div>
          <div class="item-inner">
            <div class="item-title label" >温馨提示</div>
            <div class="item-input">
             <textarea  style="color:#F00;font-weight:bold;letter-spacing:2px;font-family:'Helvetica';" >为了保证支付成功，请确保真实姓名与支付宝账号一致</textarea>
            </div>
          </div>
        </div>
      </li>
    
     
      
    </ul>
  </div>
  <div class="content-block">
    <div class="row">
      <div class="col-50"><a href="#" class="button button-big button-fill button-danger" @click="reset()">重置</a></div>
      <div class="col-50"><a href="#" class="button button-big button-fill button-success" @click="editAgent()">提交</a></div>
    </div>
  </div>
</div>

  </div>

</template>

<script>
import $ from 'zepto'
import VNav from '../../components/Nav'
import _global from '../global'

export default {
  route: {
    data ({from, next}) {
      if (from.path === '/user') {
        
        this.path = from.path
      }
    }
  },
  ready () {
    
    if (window.localStorage.getItem('user_id')) {
      self.userId = parseInt(window.localStorage.getItem('user_id'), 0)
    }
    $.init()


    this.getAgentPayInfo();
  
  },
  data () {
    return {
      path: '/user',
      title: '完善代理个人信息',
      predisabled: '',
      active: 'active',
      nextdisabled: '',
      submit:false,
      userId:0,
      id:0,
      mobile:'1111',
      name:'asdasd',
      alipayAccount:'ce'


    }
  },
  methods: {

   //获取用户支付信息
   getAgentPayInfo(){
        let self = this
      if (window.localStorage.getItem('user_id')) {
        self.userId = parseInt(window.localStorage.getItem('user_id'), 0)
        self.id = parseInt(window.localStorage.getItem('id'), 0)
      }else{
        $.alert('服务器忙，请重新登录')
      }

      // 获取代理支付信息
      this.$http.get(_global.url + '/getAgentPayInfo?id=' + self.id).then(function(res) {
        if (typeof res.data === 'string') {
          res.data = JSON.parse(res.data)
        }
        if (res.data.errcode === -999) {
         
          window.location.href = _global.url + '/wxlogin'
          return
        }

        if (res.data.errcode === 2) {
          
          $.alert('服务器忙，请稍后再试');
          return
        }


        if(res.data.errcode === 0){
          self.mobile = res.data.data.mobile;
          self.name = res.data.data.name;
          self.alipayAccount = res.data.data.alipayAccount;
          return
        }
       
      }, function(res) {
        console.log(res)
      })
   },
   //重置输入信息
    reset(){
         $('#name').val('');
         $('#alipayAccount').val('');
         $('#mobile').val('');
    } ,
    //创建俱乐部
   editAgent(button){
    let self = this

     if(self.submit){
        $.alert('已经提交了,请稍后再试');
        return
      }
      
      let name = $('#name').val();
      let mobile =  $('#mobile').val();
      let alipayAccount =  $('#alipayAccount').val();

      if(name==''|| name ==null){
        $.alert('真实姓名不能为空');
        return
      }
      
      if(alipayAccount==''||alipayAccount==null){
         $.alert('支付宝账号不能为空');
         return
      }
      if(mobile==''||mobile==null){
         $.alert('手机号码不能为空');
        return
      }
       if(mobile.length!=11){
         $.alert('手机号码只能是11位');
        return
       }
  

      if (window.localStorage.getItem('user_id')) {
        self.userId = parseInt(window.localStorage.getItem('user_id'), 0)
        self.id = parseInt(window.localStorage.getItem('id'), 0)
      }
      
       self.submit=true
    
       this.$http.get(_global.url + '/editAgentPay?id=' + self.id +'&alipayAccount='+alipayAccount +'&name='+name+'&mobile='+mobile).then(function(res) {
        if (typeof res.data === 'string') {
          res.data = JSON.parse(res.data)
        }

        self.submit=false
        if (res.data.errcode === -999) {
         
          window.location.href = _global.url + '/wxlogin'
          return
        }

        if (res.data.errcode === 2) {
       
          $.alert('服务器忙，请稍后再试');
          return
        }

        if (res.data.errcode === 1) {
         
          $.alert('参数错误');
          return
        }

        if(res.data.errcode === 0){
          {
            $.toast('操作成功...');
            self.submit=false
            //location.reload()
            return
          }
         
        }
       
      }, function(res) {
        console.log(res)
      })

    },
    //获取用户房卡数
    
    getUserGems(){

      let self = this
        if (window.localStorage.getItem('user_id')) {
          self.userId = parseInt(window.localStorage.getItem('user_id'), 0)
          self.id = parseInt(window.localStorage.getItem('id'), 0)
         
      }

       this.$http.get(_global.url + '/getUserGems?id=' + self.id +'&user_id='+self.userId).then(function(res) {
        if (typeof res.data === 'string') {
          res.data = JSON.parse(res.data)
        }
        if (res.data.errcode === -999) {
         
          window.location.href = _global.url + '/wxlogin'
          return
        }

        if (res.data.errcode === 2) {
          
          $.alert('服务器忙，请稍后再试');
          return
        }

        if(res.data.errcode === 0){
          self.user_gems = res.data.data.gems;
          
          return
        }
       
      }, function(res) {
        console.log(res)
      })



    },
  
    auditList (club_id, audit_count) {
      if(audit_count==0){
        $.alert('暂无需要审核申请');
        return
      }
     
      this.$router.go('/user/applyAudit/' + club_id)
    }
  },
  components: {
    VNav
  }
}
</script>

<style>

.label {
color:#333;
}
</style>
